package com.clothing.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.clothing.entity.Bulletin;
import com.clothing.service.BulletinService;
import com.clothing.utils.Utils;
import com.clothing.utils.page.Filter;
import com.clothing.utils.page.Order;


/**
 * @ClassName: BulletinServiceImpl 
 * @Description: TODO(Bulletin-ServiceImpl)
 * @author Charles
 * @date 2018年5月7日
 * @version 1.0
 */
@Service
public class BulletinServiceImpl extends
        BaseServiceImpl<Bulletin, Long> implements BulletinService
{
    @Override
    public List<Bulletin> findBulletinList(Boolean isShow)
    {
        if (null != isShow)
        {
            List<Filter> filters = new ArrayList<>();
            filters.add(Filter.eq("isShow", isShow));
            
            return findList(null, filters, null);
        }
        
        return findAll();
    }

    @Override
    public Bulletin findNewBulletin()
    {
        List<Filter> filters = new ArrayList<>();
        filters.add(Filter.eq("isShow", Boolean.TRUE));
        List<Order> orders = new ArrayList<>();
        orders.add(Order.desc("id"));
        List<Bulletin> bulletins = findList(1, filters, orders);
        
        if (Utils.isEmpty(bulletins))
        {
            return null;
        }
        
        return bulletins.get(0);
    }
}
